<!DOCTYPE html>
<html class="um landscape min-width-240px min-width-320px min-width-480px min-width-768px min-width-1024px">
<head>
<title></title>
<meta charset="utf-8">
<meta name="viewport" content="target-densitydpi=device-dpi, width=device-width, initial-scale=1, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<meta name="copyright" content="http://www.appcms.org" />
<link rel="stylesheet" href="skin/base.css">
<link rel="stylesheet" href="skin/form.css">
<link rel="stylesheet" href="skin/btn.css">
<script src="js/zy_control.js"></script>
<script src="js/zy_click.js"></script>
<script src="js/config.js"></script>
<script src="js/common.js"></script>
</head>
<body ontouchstart>
<div id="main" class="box-ver box">
  <div id="header">
  	<div class="title">
  		<span class="l icon back" ontouchstart="zy_touch('act')" onclick="uexWindow.close(-1);"></span>
		<span class="txt">绑定手机号</span>
	</div>
  </div>
  
  <div id="content">
    <div class="form">
    	<div class="items">
    	  <div class="item box box-hor">
            	<div class="label">手机号:</div>
            	<div class="txt">
            		<input type="number" name="mobile" id="mobile" maxlength="11" placeholder="请输入11位手机号码" />
				</div>
          </div>
		</div>
		

	  
      <div class="btn">
      	<div class="button" id="btn1" onclick="gocode();">发送验证码</div>
      </div>
	  <div class="items">
		  <div class="item box box-hor">
	        	<div class="label">激活码:</div>
	        	<div class="txt">
	        		<input type="number" name="code" id="code" maxlength="6" placeholder="请输入6位数激活码" />
				</div>
	      </div>
	  </div>

      <div class="btn">
        <div class="button" id="btn2">提交验证 </div>
      </div>
	
  </div>
</div>
</body>
<script>
    	zy_init();
		var n=60;
		var getTime;
	
		function doupdate(){
			n--;
			var btn = $$("btn1");
			if (n == 0) {
				window.clearInterval(getTime);
				btn.innerHTML='重新发送激活码';
				btn.setAttribute("onclick","gocode()");
			}
			else {
				btn.innerHTML='在<span>'+n+'</span>秒后重发激活码';
			}
		}
		
		function gocode(){
			var mobile=$$("mobile").value;
			if(!mobile.match(/^1(\d{10})$/g)){
				uexWindow.alert('', '请填写正确的手机号码', '关闭');
				return false;
			}
			var url = app_path+'index.php?m=iapp&c=user&a=getsms&userid='+localStorage['u_id']+'&acctoken='+localStorage['u_acctoken'];
			uexXmlHttpMgr.open(1,'post',url,"8000");
			uexXmlHttpMgr.setPostData(1,'0','mobile',mobile);
			uexXmlHttpMgr.send(1);
			uexWindow.toast(1, 5, '激活码获取中...', 0);
		}
		
		function checkcode(){
			var mobile = $$('mobile').value;
			if(!mobile.match(/^1(\d{10})$/g)){
				uexWindow.alert('', '请填写正确的手机号码', '关闭');
				return false;
			}
			var code = $$('code').value;
			if(code.length<4){
				uexWindow.alert('', '验证码错误', '关闭');
				return false;
			}
			var url = app_path+'index.php?m=iapp&c=user&a=checkcode&userid='+localStorage['u_id']+'&acctoken='+localStorage['u_acctoken'];
			uexXmlHttpMgr.open(2,'post',url,"8000");
			uexXmlHttpMgr.setPostData(2,'0','mobile',mobile);
			uexXmlHttpMgr.setPostData(2,'0','code',code);
			uexXmlHttpMgr.send(2);
			uexWindow.toast(1, 5, '激活码发送中...', 0);
		}
		
		window.uexOnload = function(type){
			if (!type) {
				uexXmlHttpMgr.onData = function(opId, status, data){
					uexXmlHttpMgr.close(opId);
					uexWindow.closeToast();
					
					if (status == 1) {
						data=JSON.parse(data);
						if(opId==1){
							
							 if(data['success']=='OK'){							
								uexWindow.alert('效验码获取成功',data['msg'],'关闭');				
								n=60;
								$$("btn1").setAttribute("onclick","void(0)");
								$$("btn2").setAttribute("onclick","checkcode()");
								if (data['data']) {
									$$("code").value = data['data'];
								}
								getTime=window.setInterval(function(){doupdate();},1000);
							}else{
								uexWindow.alert('效验码获取失败',data['msg'],'关闭');
							}
						}
						
						if(opId==2){
							if(data['success']=='NODATA'){
								uexWindow.alert('','参数错误','关闭');
							}else if(data['success']=='OK'){
								localStorage['u_mobile'] = $$('mobile').value;
								uexWindow.evaluatePopoverScript('more','content','oklogin("绑定手机号成功~")');
								uexWindow.close(-1);
							}else{
								uexWindow.alert('','激活码验证失败!','关闭');
							}
						}
					}else if(status==-1){
						uexWindow.alert('','提交超时!','关闭');
					}
				}
			}
		}
    </script>
</html>